from django import template

from ..models import ArticleFavorite


register = template.Library()

@register.inclusion_tag('translations/favorites/partial_favorite_case.html')
def render_favorite_case(user, article):
    article_favorite_count = ArticleFavorite.objects.filter(article=article).count()
    if user.is_authenticated():
        self_has_favorited = ArticleFavorite.objects.filter(user=user, article=article).exists()
        return {'self_has_favorited': self_has_favorited, 'article_favorite_count': article_favorite_count, 'article': article}
    else:
        return {'article_favorite_count': article_favorite_count, 'article': article}
